package com.hs.dict.dwr;
 

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.hs.core.db.DBMgr;
import com.hs.core.dwr.DwrHelper;

public class DictDwr   extends DwrHelper{
	/**
	 * 删除字典
	 * @param checkId
	 * @return
	 */
	public String delDict(String id){
		String sql = "update HS_CODE SET YOUXBJ=1 WHERE ID=?";
		int i = this.getDbo().update(sql, new Object[]{id});
		System.out.println("sql="+this.getDbo().toString());
		if(i == 0){
			return "删除失败"; 
		}
		return "操作成功";
	}
	
	
     public String defselect() {
		return "0,0";
	 }
	
	public Map<String,String> select() {
		
		String sql = "select * from HS_CODE where YOUXBJ=1 and DICTTYPE='3' and dictcode like '%0000'  order by dictcode asc";
		List list = DBMgr.getDbUtilInst().queryList(sql, null);
		Map<String,String> dictMap=new TreeMap<String, String>();
		dictMap.put("0", "请选择");
		for (int i = 0; i < list.size(); i++) {
			Map map = (Map)list.get(i);
			String name = (String)map.get("DICTNAME");
			String code = (String)map.get("DICTCODE");
			dictMap.put(code, name);
		}
		return dictMap;
	}
	
	public Map<String,String> subSelect(String preCode) {
		//System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+preCode);
		String pre = "11";
		if(preCode!=null&&preCode.length()>2)
			pre = preCode.substring(0,2);
		String sql = "select * from HS_CODE where YOUXBJ=1 and DICTTYPE='3' and dictcode like '"+pre+"%'  order by dictcode asc";
		List list = DBMgr.getDbUtilInst().queryList(sql, null);
		Map<String,String> dictMap=new TreeMap<String, String>();
		dictMap.put("0", "请选择");
		for (int i = 1; i < list.size(); i++) {
			Map map = (Map)list.get(i);
			String name = (String)map.get("DICTNAME");
			String code = (String)map.get("DICTCODE");
			dictMap.put(code, name);
		}
		return dictMap;
	
	}
}
